# from mxnet import ndarray as nd
# from mxnet import autograd
# import random
#
# num_inputs = 2
# num_examples = 1000
# true_w = [2,2]
# true_b=4
#
# x = nd.random_normal(shape=(num_examples,num_inputs))
# y = true_w[0] * x[:,0]+true_w[1]*x[:,1]+true_b
# y += 0.01* nd.random_normal(shape=y.shape)
#
# batch_size = 10
# def data_iter():
#     idx = list(range(num_examples))
#     random.shuffle(idx)
#     for i in range(0,num_examples,batch_size):
#         j= nd.array(idx[i:min(i+batch_size,num_examples)])
#         yield nd.take(x,j),nd.take(y,j)
#
#
# w = nd.random_normal(shape=(num_inputs,1))
# b = nd.zeros((1,))
# params=[w,b]
#
# for param in params:
#     param.attach_grad()
#
# def net(x):
#     return nd.dot(x,w)+b
#
# def square_loss(yhat,y):
#     return (yhat-y.reshape(yhat.shape))**2
#
# def SGD(params,lr):
#     for param in params:
#         param[:]=param-lr*param.grad
#
# epochs = 20
# learn_rate=0.005
# for e in range(epochs):
#     total_loss=0
#     for data,label in data_iter():
#         with autograd.record():
#             output=net(data)
#             loss=square_loss(output,label)
#         loss.backward()
#         SGD(params,learn_rate)
#
#         total_loss += nd.sum(loss).asscalar()
#     print(f"Epoch:{e},avarage loss:{total_loss/num_examples}")
#
# print(true_w,w)
# print(true_b,b)
#

# import torch
# x = torch.arange(12)
# print(x)
# print(x.shape)
# print(x.numel())
# x=x.reshape(3,4)
# print(x)
# y = torch.zeros((2,3,4))
# print(y)

# 创建人工数据集，并存储在csv文件
# import os
# import pandas as pd
# import  torch
# os.makedirs(os.path.join('\\','data'),exist_ok=True)
# data_file=os.path.join('\\','data','house_tiny.csv')
# with open(data_file,'w') as f:
#     f.write('NumRooms,Alley,Price\n')
#     f.write('NA,Pave,127500\n')
#     f.write('2,NA,106000\n')
#     f.write('4,NA,178100\n')
#     f.write('NA,NA,140000\n')
# data= pd.read_csv(data_file)
# print(data)
#
# inputs,outputs = data.iloc[:,0:2],data.iloc[:,2]
# inputs = inputs.fillna(inputs.mean())
# print(inputs)
#
# inputs = pd.get_dummies(inputs,dummy_na=True)
# print(inputs)
#
# x , y = torch.tensor(inputs.values),torch.tensor(outputs.values)
# print(x,y)


import torch
# A = torch.arange(24,dtype=torch.float).reshape(4,6)
# print(A)
#
# print(A.mean(axis=0))
# print(A.mean(axis=1))
# print(A.sum(axis=0))
# print(A.shape[0])
# print(A.shape[1])
# sum_A = A.sum(axis=1,keepdims=True)
# print(sum_A)
#
# a = torch.ones((2,5,4))
# print(a)
# print(a.sum(axis=2))
# print(a.sum(axis=1))
# print(a.sum(axis=2,keepdims=True))